<template>
  <div class="hot-box">
    <div class="title">热搜榜</div>
    <ul class="hot-list">
      <li class="hot-item" v-for="(item, index) in hotList" :key="index" @click="handleHotMusic(index)">
        <span>{{ index + 1 }}</span>
        <p>{{ item.searchWord }}</p>
      </li>
    </ul>
  </div>
</template>

<script setup lang="ts">
import { searchHotList } from "@/service/api/musicRequest";
import type { ISearchHotWords } from "@/types/music/searchHotType";
import { ref, onMounted } from "vue";
const emit = defineEmits<{
  (e: "searchMusic", item: string): void;
}>();
const hotList = ref<ISearchHotWords[]>([]);

onMounted(() => {
  searchHotList().then((res) => {
    hotList.value = res.data;
  });
});

const handleHotMusic = (index: number) => {
  emit("searchMusic", hotList.value[index].searchWord);
};
</script>

<style scoped lang="scss">
.hot-box {
  width: 100%;
  box-sizing: border-box;
  padding: 15px;
  .title {
    margin-bottom: 15px;
    font-size: 18px;
  }
  .hot {
    &-list {
      display: flex;
      width: 100%;
      flex-wrap: wrap;
    }
    &-item {
      display: flex;
      align-items: center;
      width: 50%;
      margin-top: 20px;
      font-size: 16px;
      p {
        margin: 0;
        margin-left: 10px;
      }
    }
  }
}
</style>
